<!-- Nav Bar -->
<div id="navbar" class="center">
<?php
// The following section is responsible for finding the current document and bolding the link to indicate that it is active.
// Set up the footer links string.
$navbarKeys = array('home');
$navbarLinks = array('home' => 'Home');
$navbarUrls = array(
	'home' => array('controller' => 'users', 'action' => 'index')
);

// Create additional links if there is anyone logged in.
$loggedIn = $session->read('Auth.User.username');
if($loggedIn != '') {
	if($session->read('Auth.User.group_id') == 1) {
		$navbarKeys = array_merge($navbarKeys, array('audiences', 'surveys', 'audiencelists'));
		$navbarLinks = array_merge($navbarLinks, array('audiences' => 'Audience Portal', 'surveys' => 'Surveys', 'audiencelists'=>'Audience Lists'));
		$navbarUrls = array_merge($navbarUrls, array(
			'audiences' => array('controller' => 'audiences', 'action' => 'index'),
			'surveys' => array('controller' => 'surveys', 'action' => 'index'),
			'audiencelists' => array('controller' => 'audiencelists', 'action' => 'index')
		));
	}
	$navbarKeys = array_merge($navbarKeys, array('logout'));
	$navbarLinks = array_merge($navbarLinks, array('logout' => 'Logout'));
	$navbarUrls = array_merge($navbarUrls, array(
		'logout' => array('controller' => 'users', 'action' => 'logout')
	));
} else {
	$navbarKeys[] = 'register';
	$navbarLinks['register'] = 'Register';
	$navbarUrls['register'] = array('controller' => 'users', 'action' => 'register');
	$navbarUrls['home'] = array('controller' => 'users', 'action' => 'login');
}

// The current document.
// Find the positions necessary for the operation.
$curDocName = basename(ROUTER::url('', false));
$navLinks = '';

$valid = false;
foreach($navbarKeys as $navbarKey) {
	if($curDocName == $navbarKey) {
		$valid = true;
	}
}

if(!$valid) {
	if($curDocName == 'login' || $curDocName == '' || $curDocName == 'audiences' || $curDocName == 'presenters') {
		$curDocName = 'home';
		$valid = true;
	}
}

for($i = 0; $i < count($navbarKeys); $i++) {
	if($curDocName == $navbarKeys[$i]) {
		$navLinks .= '<span class="bold">'.$navbarLinks[$navbarKeys[$i]].'</span>';
	} else {
		$navLinks .= $html->link($navbarLinks[$navbarKeys[$i]], $navbarUrls[$navbarKeys[$i]], array('class' => 'navbar'));
	}
	
	if($i + 1 != count($navbarKeys)) {
		$navLinks .= ' | ';
	}
}

echo($navLinks.'<br />');
?>
</div>
<!-- Nav Bar -->
